package borrower

import (
	"NovelBook/logic/book"
	"NovelBook/utils/auth"
	"NovelBook/utils/response"
	"github.com/gin-gonic/gin"
	"net/http"
)

// GetBorrowedInfo 获取借书情况
//
//	@Summary		获取借书情况
//	@Description	获取当前登录Borrower的借书情况，包含信息有书籍、借阅开始时间、借阅截止时间、是否归还。
//	@Tags			Borrower
//	@Accept			json
//	@Produce		json
//	@Security		ApiKeyAuth
//	@Param			Authorization	header		string									true	"`Bearer Token` 使用空格分隔`Bearer`与`Token`"
//	@Success		200				{object}	msg.Code1000{data=[]models.BorrowInfo}	"获取成功，在`data`字段保存借书情况"
//	@Failure		400				{object}	msg.Code1001							"请求参数错误"
//	@Failure		401				{object}	msg.Code1005							"无效的`Token`"
//	@Failure		503				{object}	msg.Code1003							"系统繁忙，请稍后再试"
//	@Router			/borrower/borrowed/info [get]
func GetBorrowedInfo(c *gin.Context) {
	idAny, exist := c.Get(auth.UserIDKey)
	id := idAny.(uint)
	if !exist || id < 1 {
		response.Fail(c, http.StatusUnauthorized, response.CodeTokenInvalid)
		return
	}
	borrows, err := book.GetBorrowedInfoByBorrowerID(id)
	if err != nil {
		response.FailWithMsg(c, http.StatusInternalServerError, response.CodeSystemBusy, err.Error())
		return
	}
	response.Success(c, borrows)
}
